<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>商品分类</title>
    <link rel="stylesheet " href="/tpmishop/Public/css/bootstrap.min.css ">
    <link rel="stylesheet " href="/tpmishop/Public/h-ui.admin/css/category.css ">
    <script src="/tpmishop/Public/js/jquery.min.js "></script>
    <script src="/tpmishop/Public/js/bootstrap.min.js "></script>
    <script src="/tpmishop/lib/layer/2.4/layer.js "></script>
</head>

<body>
    <div class="breadcrumb-wrap container-fluid">
        <ol class="breadcrumb pull-left">
            <li><a href="#">后台管理</a></li>
            <li class="active">商品分类</li>
        </ol>
        <a href="<?php echo U('Goods/add_category');?>" class="pull-right add-category">添加分类</a>
    </div>
    <table class="table table-hover table-bordered table-alex">
        <tr style="background-color: #E5F6FE" align="center">
            <td>分类ID</td>
            <td>分类名称</td>
            <td>分类描述</td>
            <td>上级分类</td>
            <td>排序</td>
            <td>操作</td>
        </tr>
        <?php if(is_array($data)): foreach($data as $key=>$val): ?><tr align="center">
                <td><?php echo ($val["cat_id"]); ?></td>
                <td><?php echo (str_repeat('&emsp;',$val["level"]*3)); echo ($val["cat_name"]); ?></td>
                <td><?php echo ($val["cat_desc"]); ?></td>
                <td>
                    <?php if($val["parent_name"] == null): ?>顶级分类
                        <?php else: echo ($val["parent_name"]); endif; ?>
                </td>
                <td><?php echo (str_repeat('&emsp;',$val["level"]*4)); ?>
                    <input type="text" name="sort[1]" value="<?php echo ($val["sort_order"]); ?>" sid="<?php echo ($val["cat_id"]); ?>" class="sort-input">
                </td>
                <td><a href="<?php echo U('edit_category',array('id'=>$val['cat_id']));?>">编辑</a> | <a href="javascript:;" data-id=<?php echo ($val["cat_id"]); ?> class="category-del">删除</a></td>
            </tr><?php endforeach; endif; ?>
    </table>
    <div class="container-fluid" align="center">
      <ul class="pagination">
        <?php echo ($show); ?>
    </ul>  
    </div>
     
</body>

</html>
<script type="text/javascript">
$(function() {
	// 删除商品的提示
    $(".category-del").on('click', function() {
        var id = $(this).attr('data-id');
        console.log(id);
        layer.confirm('您真的要删除吗?', {
            btn: ['删除', '取消'] //按钮
        }, function() {
            $.get('/tpmishop/Admin/Goods/del_category/id/' + id, function(data) {
                if (data == 1) {
                    layer.msg("删除成功", { time: 1000 }, function() {
                        location.reload();
                    });
                } else {
                    layer.msg("删除失败");
                }
            });
        }, function() {
        });
    })
    // 修改排序
    $(".sort-input").on('blur', function() {
        // 获取修改的要修改的id
        var sid = $(this).attr('sid');
        // 获取要修改的值
        var sortVal = $(this).val();
        console.log(sid);
        console.log(sortVal);
        // ajax刷新
        $.ajax({
            // 显示三步走
            // 去和谁交互
            url: "<?php echo U('Admin/Goods/navSort');?>",
            // 怎么交互get或者post
            type: 'post',
            // 把什么东西给他
            data: { "sid": sid, "sortVal": sortVal },
            // 以什么格式传输
            dataType: 'json',
            // 如果成功怎么样
            success: function(data) {
                if (data.status == -1) {
                    alert(data.info);
                } else if (data.status == 1) {
                    location.reload();
                } else {
                    alert(data.info);
                }
            }
        })

    })
});
</script>